﻿using System;
using System.Collections.Generic;
using DbSharp.Framework.TestEngine;

namespace DbSharp.ConsoleRunner
{
    internal sealed class CompositeTestCaseStatusNotify
        : ITestCaseStatusNotify
    {

        private readonly List<ITestCaseStatusNotify> m_inner =
            new List<ITestCaseStatusNotify>();
        private TestRunnerBase m_testRunner;

        #region ITestCaseStatusNotify Members

        public TestRunnerBase TestRunner
        {
            get { return m_testRunner; }
            set
            {
                m_testRunner = value;
                foreach (var item in m_inner)
                    item.TestRunner = value;
            }
        }

        public void UpdateStatus(TestCaseStatusNotifyEventArgs arg)
        {
            foreach (var item in m_inner)
                item.UpdateStatus(arg);
        }

        #endregion

        #region IDisposable Members

        public void Dispose()
        {
            foreach (var item in m_inner)
                item.Dispose();
        }

        #endregion

        public void Add(ITestCaseStatusNotify notifier)
        {
            if (notifier == null)
                throw new ArgumentNullException("notifier");
            notifier.TestRunner = m_testRunner;
            m_inner.Add(notifier);
        }

    }
}
